package com.boss.core.manage;

import org.kohsuke.stapler.DataBoundConstructor;

import java.util.List;

/**
 * Server section
 * @author Momin Noor Khan
 */
public class BossServer implements Comparable<BossServer>{
    private String serverName;
    private boolean disabled;
    private List<BossPort> ports;

    private transient int hashCode = 0;

    @DataBoundConstructor
    public BossServer(String serverName, boolean disabled, List<BossPort> ports) {
        this.serverName = serverName;
        this.disabled = disabled;
        this.ports = ports;
    }

    public String getServerName() {
        return this.serverName;
    }

    public void setServerName(String serverName){
        this.serverName = serverName;
    }

    public boolean isDisabled() {
        return disabled;
    }

    public void setDisabled(boolean disabled){
        this.disabled = disabled;
    }

    public List<BossPort> getPorts() {
        return ports;
    }

    public void setPorts(List<BossPort> ports){
        this.ports = ports;
    }

    public int compareTo(BossServer otherServer) {
        String svrName = ((BossServer) otherServer).getServerName();
        return (this.getServerName()).compareTo(svrName);
    }

    @Override
    public boolean equals(Object obj){
        if(this == obj){
            return true;
        }

        if(!(obj instanceof BossServer)){
            return false;
        }

        BossServer server = (BossServer)obj;

        if(!this.getServerName().equalsIgnoreCase(server.getServerName())){
            return false;
        }
        return true;
    }

    @Override
    public int hashCode(){
        final int multiplier = 11;
        if(hashCode == 0){
            int code = 123;
            code = multiplier*code + serverName.hashCode();
            hashCode = code;
        }
        return hashCode;
    }
}
